{include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/header.html"}
{literal}
<script type="text/javascript" src="/js/jquery.autocom.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jquery.datetimepicker.css" />
<script type="text/javascript" src="/js/jquery.datetimepicker.js"></script>
<script type="text/javascript">
    $(function(){
        $('.assortment').hover(function(){
            $('.assort_list').stop().fadeIn();
        },function(){
            $('.assort_list').stop().fadeOut();
        });
    });
    $(function(){
        $('.login').click(function(){
            $(".userlogin").show();
        })
        $('.overlay-close').click(function(){
            $(".userlogin").hide();
        })
    })

    $(function(){
        $(".rs_list_input3").click(function(){
            var demand =  $("textarea[name=demand]").val();
            var business_name =  $("input[name=business_name]").val();
            var realname =  $("input[name=realname]").val();
            var phone = $('input[name=phone]').val();

            if(demand==''){
                alert("请填写求购内容！"); return false;
            }
            if(business_name==''){
                alert("请填写求购公司！"); return false;
            }
            if(realname==''){
                alert("请填写求购联系人！"); return false;
            }
            if(phone==''){
                alert("请填写求购联系电话！"); return false;
            }

            if(phone.length!=11 ){
                alert("联系电话填写不正确"); return false;
            }
            $.ajax({
                url:'/buy/noLoginBuy',
                data:{demand:demand,business_name:business_name,realname:realname,phone:phone},
                type:'POST',
                success:function(data){
                    var data = eval("("+data+")");
                    var code = data.code;
                    var msg = data.msg;
                    if(code == 1){
                        alert(msg);
                        return;
                    }
                    if(code == 2){
                        alert(msg);
                        return;
                    }
                    if(code == 5){
                        alert(msg);
                        return;
                    }
                    if(code == 7){
                        alert(msg);
                        return;
                    }
                    if(code == 8){
                        alert(msg);
                        return;
                    }
                    if(code == 3){
                        alert("发布成功");
                        window.location.reload();
                    }
                },
                dataType:'text'
            });
        });
    });

    function change_code(){
        var img = document.getElementById('login_code_img');
        img.src = '/login/code/rand/' + Math.random();
    };

    $(function(){
        $(".popup_btn1").click(function(){
            var username =  $("input[name=username]").val();
            var password =  $("input[name=password]").val();
            var code =  $("input[name=code]").val();
            var back_url = window.location.href;
            $.ajax({
                url:'/login/login',
                data:{username:username,password:password,code:code},
                type:'POST',
                success:function(data){
                    var data = eval("("+data+")");
                    var codes = data.code;
                    if(codes == 1004){
                        alert(data.msg);
                        change_code();
                        return;
                    }
                    if(codes == 1008){
                        window.location.href=back_url;
                    }else{
                        alert(data.msg);
                        return;
                    }
                    return false;
                },
                dataType:'text'
            });
        });
    });


    $(document).delegate(".quotes","click",function(){
        var buy_id = $(this).attr("buy_id");
        var product_id = $(this).attr("product_id");
        var cate_name = $(this).attr("cate_name");
        var product_name = $(this).attr("product_name");
        var brand_name = $(this).attr("brand_name");
        var num = $(this).attr("num");
        var price = $(this).attr("price");
        var delivery_area = $(this).attr("delivery_area");
        var p_id = $(this).attr("p_id");
        var delivery_time =$(this).attr("delivery_time");
        if(delivery_time.length==0){ delivery_time="---" }
        var user_id = 0;
        quote_htmls(buy_id,user_id,product_id,cate_name,product_name,brand_name,num,price,delivery_area,p_id,delivery_time);
        $('.overlay-close').click(function(){
            $(".remove").hide();
        })
    });

    $(document).delegate(".popup_btn", "click", function(e){
        e.preventDefault();
        var buy_id = $("input[name=buy_id]").val();
        var product_id = $("input[name=product_id]").val();
        var price = $("input[name=price]").val();
        var num = $("input[name=num]").val();
//        var deliveryarea = $("input[name=deliveryarea]").val();
        var content = $("#contents").val();
        var user_id = $("input[name=user_id]").val();
        var delivery_time = $("input[name=delivery_time]").val();
        var url = "/json/save_quote";
        $.post(url, {
            price:price,
            num:num,
//            delivery_area:deliveryarea,
            buy_id: buy_id,
            user_id:user_id,
            product_id:product_id,
            content: content,
            delivery_time:delivery_time
        },function(data){
            var data = eval("("+data+")");
            var code = data.code;
            var msg = data.msg;
            if(code == 8){
                var html = "<div style='color:#007750; text-align: center; padding: 20px 0px;'>"+msg+"</div>" ;
                //这边这样做是为了防止点击下一个弹框的信息覆盖
                $(".brandMsgTips").html(html);
                window.location.reload();
            }else{
                $(".quote_msg").html(msg);
            }
        });
        setTimeout(function(){window.location.reload();},3000);
    });

    function quote_htmls(buy_id,user_id,product_id,cate_name,product_name,brand_name,num,price,delivery_area,p_id,delivery_time){
        var html = "<div class=\"mui-dialog-mask remove\" ></div>";
        html += "<div class=\"mui-dialog remove\" style=\'width:500px; height: 460px; left:50%; top:50%;margin-top:-240px;position:fixed;margin-left:-250px; \' >";
        html += "<a href=\"javascript:void(0)\" class=\"overlay-close\"></a>";
        html += "<div class=\"mui-diglog-wrap\">";
        html += "<div class=\"mui-dialog-header\">我要报价</div>";
        html += "<div class=\"mui-dialog-body\">";
        html += "<div class=\"brandMsgTips\" style='margin: 5px 15px; padding: 0px;'>";
        html += "<form action='' method='post'>";
        html += " <input type=\"hidden\" name=\"product_id\" class=\"product_id\" value=\""+product_id+"\">";
        html += " <input type=\"hidden\" name=\"buy_id\" class=\"buy_id\" value=\""+buy_id+"\">";
        html += " <input type=\"hidden\" name=\"user_id\" class=\"user_id\" value=\""+user_id+"\">";
        html += " <input type=\"hidden\" name=\"p_id\" class=\"p_id\" value=\""+p_id+"\">";
        html += "<h3 class=\"orange tac fwb\">求购：<span>"+cate_name+' '+product_name+' '+brand_name+' '+num+' '+price+' '+delivery_area+"</span></h3>";
        html +="<ul class=\"mui_dl_list\">";
        html += "<li>　　价格：<input type=\"text\" class=\"popup_text\" value="+price+" name=\"price\"></li>";
        html += "<li>　　数量：<input type=\"text\" class=\"popup_text\" value="+num+" name=\"num\"></li>";
//        html += "<li>　交货地：<input type=\"text\" class=\"popup_text\" disabled value='"+delivery_area+"' name=\"deliveryarea\"></li>";
        html += "<li>交货时间：<input type=\"text\" class=\"popup_text\" disabled value="+delivery_time+" id=\"datetimepicker\" name=\"delivery_time\"></li>";
        html += "<li>　　备注：<textarea  class=\"popup_text\" name=\"content\" id=\"contents\"></textarea></li>";
        html += "<li class=\"pl30p \"><input class=\"popup_btn\" type='submit' value='提交报价'></li>";
        html +="</u>";
        html += "<div class='quote_msg red'></div>";
        html += "</div>";
        html += "</div>";
        html += "</div>";
        html += "</div>";
        html += "</form>";
        html += "<div class=\"mui-dialog-skin remove\"></div>";
        $("body").append(html);
        $('#datetimepicker').datetimepicker({
            onGenerate:function( ct ){
                $(this).find('.xdsoft_date')
                        .toggleClass('xdsoft_disabled');
            },
            lang:'ch',
            timepicker:false,
            format:'Y-m-d',
            formatDate:'Y-m-d',
//            minDate:'-1970/01/01',
            maxDate:'+1970/01/01',
            timepicker:false,
            todayButton:true, // 2.1.0
        });
    }

</script>
<style>
    .assort_list{display: none;}
</style>
{/literal}

<div class="search_list">
    <div class="search_crumbs">
        <p class="fl">全部结果<i class="ffs">></i></p>
        {if $cate_name <> ''}
        <p class="fl crumbattr"><a href="/buy/index?kd={$kd}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&product_name={$product_name}&list_search ={$list_search}&order={$order}">品种：{$cate_name}<i class="close">关闭</i></a></p>
        {/if}
        {if $currency_name <> ''}
        <p class="fl crumbattr"><a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&product_name={$product_name}&list_search ={$list_search}&order={$order}">币种：{$currency_name}<i class="close">关闭</i></a></p>
        {/if}
        {if $area_name <> ''}
        <p class="fl crumbattr"><a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&region_name={$region_name}&brand_name={$brand_name}&product_name={$product_name}&list_search ={$list_search}&order={$order}">交货地：{$area_name}<i class="close">关闭</i></a></p>
        {/if}
        <p class="fl"><i class="ffs">></i></p>
        <form method="get" action="">
            <input type="hidden" class="orit" name="cate_name" value="{$cate_name}"/>
            <input type="hidden" class="orit" name="kd" value="{$kd}"/>
            <input type="hidden" class="orit" name="currency_name" value="{$currency_name}"/>
            <input type="hidden" class="orit" name="area_id" value="{$area_id}"/>
            <input type="hidden" class="orit" name="area_name" value="{$area_name}"/>
            <p class="fl crumbattr_search"><input type="text" name="list_search" value="{$list_search}" placeholder="在当前条件下搜索" class="crumbsearch-input"/><input class="crumbsearch-btn" value="" type="submit"/></p>
        </form>
        <p class="fr">共<span class="blue fwb fs16" id="total">{$totalnum}</span>件相关商品</p>
    </div>

    <div class="nav_prop">
        {if $cate_name eq ''}
        <div class="nav_variety">
            <span class="fl">品　种</span>
            <div class="search_wrap_text">
                {if $cate<>''}
                {foreach from=$cate key=key item=item}
                <a href="/buy/index?kd={$kd}&cate_name={$item.cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&product_name={$product_name}&list_search={$list_search}&order={$order}" title="{$item.cate_name}" cate_name="{$item.cate_name}">{$item.cate_name}</a>
                {/foreach}
                {/if}
            </div>
        </div>
        {/if}
        {if $currency_name eq ''}
        <div class="nav_rmb">
            <span class="fl">币　种</span>
            <div class="search_wrap_text">
                {if $CurrencyShow<>''}
                {foreach from=$CurrencyShow key=key item=item}
                <a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$item.name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&product_name={$product_name}&list_search={$list_search}&order={$order}" title="{$item.name}"  currency_name="{$item.name}">{$item.name}</a>
                {/foreach}
                {/if}
            </div>
        </div>
        {/if}
        {if $area_name eq ''}
        <div class="nav_area">
            <span class="fl">交货地</span>
            <div class="search_wrap_text">
                <div class="search_te">
                    {if $AreaShow<>''}
                    {foreach from=$AreaShow key=key item=item}
                    <a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$item.area_id}&area_name={$item.area_name}&region_name={$region_name}&brand_name={$brand_name}&product_name={$product_name}&list_search={$list_search}&order={$order}" title="{$item.area_name}"  area_id="{$item.area_id}" area_name="{$item.area_name}" >{$item.area_name}</a>
                    {/foreach}
                    {/if}
                </div>
                {if $CountArea>9}
                <div class="swt_text stms1"><span>更多</span><i></i></div>
                {/if}
            </div>
        </div>
        {/if}
        <div class="search_prot">
            <form name="" action="" method="get">
                <input type="hidden" class="orit" name="currency_name" value="{$currency_name}"/>
                <input type="hidden" class="orit" name="kd" value="{$kd}"/>
                <input type="hidden" class="orit" name="area_id" value="{$area_id}"/>
                <input type="hidden" class="orit" name="area_name" value="{$area_name}"/>
                <input type="hidden" class="orit" name="cate_name" value="{$cate_name}"/>
                <input type="hidden" class="orit" name="list_search" value="{$list_search}"/>
                <input type="hidden" class="orit" name="order" value="{$order}"/>
                品种：<input type="text" class="orit" name="cate_name" value="{$cate_name}"/>
                交货地：<input type="text" class="orit" name="area_name" value="{$area_name}"/>
                牌号：<input type="text" class="orit" name="product_name" value="{$product_name}"/>
                厂商：<input type="text" class="orit" name="brand_name" value="{$brand_name}"/>
                <input class="orit_btn" type="submit" value="搜 索"/>
            </form>
        </div>

    </div>

        <div class="search_text_wrap">
            <div class="search_menb">
            <div class="relsearch">
                {if $order eq ''}
                <a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&delivery_area={$delivery_area}&product_name={$product_name}&list_search={$list_search}" class="fsort curr">综合<i></i></a>
                {else}
                <a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&delivery_area={$delivery_area}&product_name={$product_name}&list_search={$list_search}" class="fsort">综合<i></i></a>
                {/if}
                {if $order eq 'numdesc'}
                <a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&delivery_area={$delivery_area}&product_name={$product_name}&list_search={$list_search}" class="fsort curr">数量<i></i></a>
                {else}
                <a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&delivery_area={$delivery_area}&product_name={$product_name}&list_search={$list_search}&order=numdesc" class="fsort">数量<i></i></a>
                {/if}
                {if $order eq 'pricedesc'}
                <a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&delivery_area={$delivery_area}&product_name={$product_name}&list_search={$list_search}" class="pirce curr curr1">价格<i></i></a>
                {else if $order eq 'priceasc' }
                <a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&delivery_area={$delivery_area}&product_name={$product_name}&list_search={$list_search}&order=pricedesc" class="pirce curr">价格<i></i></a>
                {else}
                <a href="/buy/index?kd={$kd}&cate_name={$cate_name}&cates_name={$cates_name}&currency_name={$currency_name}&area_id={$area_id}&area_name={$area_name}&region_name={$region_name}&brand_name={$brand_name}&delivery_area={$delivery_area}&product_name={$product_name}&list_search={$list_search}&order=priceasc" class="pirce">价格<i></i></a>
                {/if}
                <form name="" action="" method="get" class="fl">
                    <div class="ppld_input">
                        <input type="hidden" class="orit" name="kd" value="{$kd}"/>
                        <input type="hidden" class="orit" name="cate_name" value="{$cate_name}"/>
                        <input type="hidden" class="orit" name="area_name" value="{$area_name}"/>
                        <input type="hidden" class="orit" name="product_name" value="{$product_name}"/>
                        <input type="hidden" class="orit" name="brand_name" value="{$brand_name}"/>
                        <input type="hidden" class="orit" name="delivery_area" value="{$delivery_area}"/>
                        <input type="text" name="minprice" value="{$minprice}" placeholder="¥最低价"/>-
                        <input type="text" name="maxprice" value="{$maxprice}" placeholder="¥最高价"/>
                    </div>
                    <input type="submit" class="ppld_btn" value="确定"/>
                </form>
                <div class="ppld_flip">
                    {$linkpage}
                </div>
            </div>
                </div>
        </div>

        <div class="material">
            <div class="material_left">
                <ul>
                    {if !$buydata}
                    <li class="tac pt10 pb10">暂无信息</li>
                    {else}
                    {foreach from=$buydata key=key item=item}
                    <li class="{if $item.status==2 || $item.status==3}{else}curr{/if}">
                        <div class="matl_ph">
                            <div class="matl_content">
                                <p class="tac white">{$item.cate_name}</p>
                                <p class="tac wt mt10">{$item.brand_name}</p>
                                <p class="fwb wt tac mt10">{$item.product_name}</p>
                                <p class="tac wt mt10"><span class="mt_dw">{$item.num}吨</span></p>
                            </div>
                        </div>
                        <div class="matl_pt">
                            <p class="pt5"><span class="pr20">求购:{$item.num}吨</span><span class="pr20">{$item.cate_name}</span><span class="pr20">{$item.product_name}</span>意向价格：<span class="orange fs20 fwb">{$item.price}</span><span class="orange pl5">元/吨</span></p>
                            <p class="pt5"><span class="pr20">厂家：{$item.brand_name}</span><span>交货地：{$item.area_name}</span></p>
                            <p class="pt5">交易员：{$item.contacts} {$item.mobile}<a target="_Blank" href="http://wpa.qq.com/msgrd?v=3&uin={$item.qq}&site=qq&menu=yes"><img class="ml5" src="/images/login_qq.png" /></a></p>
                            <p class="gray pt5">更新时间：{$item.update_time}</p>
                        </div>

                        <div class="matl_fr">
                            <p class="tac blue fs16">{if $item.status neq ''}{$_BuyStartMean[$item.status]}{/if}</p>
                            <p class="{if $item.status==2 || $item.status==3}tac pt10 btn_quote{else}tac pt10{/if}">
                                {if $userInfo}
                                <a href="javascript:void (0)" id="time" class="{if $item.status==2 || $item.status==3}quotes{else}error{/if}" product_id="{$item.product_id}" cate_name="{$item.cate_name}" product_name="{$item.product_name}" brand_name="{$item.brand_name}" num="{$item.num}"  p_id="{if !empty($item.p_id)}{$item.p_id}{/if}"  price="{$item.price}" delivery_time="{$item.delivery_time}" delivery_area="{$item.delivery_area}" buy_id="{if !empty($item.id)}{$item.id}{/if}">我要报价</a>
                                {else}
                                <a href="javascript:void (0)" class="login">我要报价</a>
                                {/if}
                            </p>
                        </div>
                    </li>
                    {/foreach}
                    {/if}
                </ul>
                <div class="page rac ptb10p">{$links}</div>
            </div>
            <div class="material_right">
                <div class="release_source rsf2" style="border-bottom:1px solid #d2d2d2;">
                    <h3 class="rs_title">免登录快速发布求购</h3>
                    <div class="rs_list">
                        <textarea name="demand" class="rs_list_input1" cols="" rows="" placeholder="写下您的真实需求，包括品种、牌号、价格、厂家等，收到后我们会立即给您回电确认，剩下的就交给我们吧。"></textarea>
                        <input name="business_name" class="rs_list_input2" type="text" placeholder="请输入公司名称"/>
                        <input name="realname" class="rs_list_input2" type="text" placeholder="请输入联系人姓名"/>
                        <input name="phone" class="rs_list_input2" type="text" placeholder="请输入您的手机号"/>
                        <input class="rs_list_input3"  type="button" value="发布货源信息"/>
                    </div>
                </div>

                <div class="trade_dynamics">

                    <h3 class="trade_dynamics_title">交易<i class="blue">动态</i></h3>
                    <ul class="trade_dynamics_list tdl_gray">
                        <li class="tdl_grade">采购内容</li>
                        <li class="tdl_price">价格</li>
                        <li class="tbl_state">交易状态</li>
                    </ul>

                    <ul class="trade_dynamics_list">
                        {foreach from=$recent key=key item=item}
                        <li>
                            <span class="tdl_grade">{$item.product_name}</span>
                            <span class="tdl_price orange">￥{round($item.price)}</span>
                            <span class="{if $item.status==6 }tbl_state blue{else}tbl_state{/if}">{if $item.status neq ''}{$_BuyStartMean[$item.status]}{/if}</span>
                        </li>
                        {/foreach}
                    </ul>
                </div>
            </div>
        </div>
    </div>
{if !$userInfo}
<div class="mui-dialog-mask remove dn userlogin"></div>
<div class="mui-dialog remove userlogin dn" style="width:500px;height:420px; left:50%; top:50%;margin-top:-150px;position:fixed;margin-left:-250px; ">
    <a href="#" class="overlay-close"></a>
    <div class="mui-diglog-wrap">
        <div class="mui-dialog-header">用户登录</div>
        <div class="mui-dialog-body">
            <ul class="mui_dl_list">
                <li>　用户名：<input name="username" class="popup_text" type="text" placeholder="请输入用户名"/></li>
                <li>　密　码：<input name="password" class="popup_text" type="password" placeholder="请输入密码"/><input type="hidden" name="back_url" value="{$back_url}"/></li>
                <li>　验证码：<input name="code" class="popup_text" style="width: 100px" type="text" placeholder="请输入验证码"/><img src="/login/code" class="ml10 vam change_mcode" id="login_code_img" onclick="change_code()" width="135" height="36"  /></li>
                <li class="third_party"><div><i>第三方账号登录</i></div></li>
                <li class="tac pt20"><a href="/login/qqlogin"><img class="ml5" alt="QQ登录" src="/images/login_qq.jpg"></a><a href="/login/sinalogin"><img class="ml10" src="/images/sian.jpg"></a></li>
                <li class="pl30p"><input class="popup_btn1" type="button" value="登录"/></li>
            </ul>
        </div>
    </div>
    <div class="mui-dialog-skin"></div>
        {/if}
    </div>


    {include file = $smarty.const.APPLICATION_PATH|cat:"/application/views/footer.html"}